<?php

namespace common\entities\common;

use common\entities\ConfigEntity;
use Yii;

/**
 * This is the model class for table "myscrm_application".
 *
 * @property string $ApplicationId
 * @property string $UniqueName
 * @property string $FriendlyName
 * @property string $WxUrl
 * @property string $YkUrl
 * @property integer $IsThird
 * @property string $DeveloperName
 * @property string $ApplicationVersion
 * @property string $Description
 * @property string $CreatedOn
 * @property string $ModifiedOn
 * @property string $VersionNumber
 * @property string $SfhqUrl
 * @property string $ZdydUrl
 * @property string $Category
 * @property string $Application
 * @property integer $EnableSubProject
 */
class MyscrmApplicationEntity extends ConfigEntity
{

    /* begin 应用CODE定义，在myscrm_application表中有记录 */
    const WLS = '5001';     // 微楼书
    const YDXS = '5002';    // 移动销售
    const QMYX = '5003';    // 全民营销
    const XMF = '5008';     // 小蜜蜂
    const WLS_NEW = '5009'; // 微楼书新版
    const SECKILL = '5020'; // 秒杀
    const WCB = '5030'; // 旺财宝
    const RCLC = '5021'; // 认筹理财
    /* end 应用CODE定义，在myscrm_application表中有记录 */

    const LOW_VERSION_YDXS = "移动销售"; //低版本的移动销售app的名称

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'myscrm_application';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['ApplicationId', 'UniqueName', 'FriendlyName', 'WxUrl', 'YkUrl', 'IsThird', 'CreatedOn', 'ModifiedOn', 'VersionNumber'], 'required'],
            [['IsThird', 'EnableSubProject'], 'integer'],
            [['CreatedOn', 'ModifiedOn'], 'safe'],
            [['ApplicationId'], 'string', 'max' => 36],
            [['UniqueName', 'FriendlyName', 'DeveloperName', 'ApplicationVersion'], 'string', 'max' => 64],
            [['WxUrl', 'YkUrl', 'SfhqUrl', 'ZdydUrl'], 'string', 'max' => 512],
            [['Description'], 'string', 'max' => 1024],
            [['VersionNumber'], 'string', 'max' => 8],
            [['Category', 'Application'], 'string', 'max' => 30]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'ApplicationId' => 'Application ID',
            'UniqueName' => 'Unique Name',
            'FriendlyName' => 'Friendly Name',
            'WxUrl' => 'Wx Url',
            'YkUrl' => 'Yk Url',
            'IsThird' => 'Is Third',
            'DeveloperName' => 'Developer Name',
            'ApplicationVersion' => 'Application Version',
            'Description' => 'Description',
            'CreatedOn' => 'Created On',
            'ModifiedOn' => 'Modified On',
            'VersionNumber' => 'Version Number',
            'SfhqUrl' => 'Sfhq Url',
            'ZdydUrl' => 'Zdyd Url',
            'Category' => 'Category',
            'Application' => 'Application',
            'EnableSubProject' => 'Enable Sub Project',
        ];
    }
    
    /**
     * 根据应用id,获取应用对象
     * @param string $applicationId 应用id
     * @return MyscrmApplicationEntity
     */
    public static function getApplicationByApplicationId($applicationId) {
    	return self::find()->where(['ApplicationId'=>$applicationId])->one();
    }

    /**
     * 根据$uniqueName获取app
     * @param $uniqueName
     * @return array|null|\yii\db\ActiveRecord
     */
    public static function getApplicationByUniqueName($uniqueName){
        return self::find()->where(['UniqueName'=>$uniqueName])->one();
    }

}
